import { Message, Notification, MessageBox } from 'element-ui';
import { getMaxZIndex } from '@/utils/mydialogUtils.js';
import { createUUID } from '@/utils/index';

export function successAlert(str) {
  Notification.success(str);
}

export const alertSuccess = successAlert;

export function failAlert(str) {
  if (!str) {
    return false;
  }
  Notification.warning(str);
}

export const alertFail = failAlert;

export function alertConfirm(message, options = {
  customClass: 'customClassAlertConfirm',
}) {
  var customClass = options && options.customClass;
  if(!customClass){
    customClass = `customClassAlertConfirm${createUUID()}`;
  }
  
/*  setTimeout(() => {
    $(`.${customClass}`).parent('.el-message-box__wrapper').css({ zIndex: getMaxZIndex() });
  }, 300);*/

  return MessageBox.confirm(message, '提示', {
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    type: 'warning',
    ...options,
    customClass
  });
}


export function alertWithPaylod(payload) {
  if (payload && payload.message) {
    failAlert(payload.message);
    return payload;
  }

  if (payload.success) {
    successAlert('操作成功');
  }

  return payload;
}
